package com.chi.thread.threadpool;

import com.chi.thread.thread.MyCallable;
import com.chi.thread.thread.MyThread;

import java.util.concurrent.*;

/**
 * @author chi  2017-06-22 22:19
 **/
public class MyThreadPool  {
    private ExecutorService executorService = new ThreadPoolExecutor(1,2,10, TimeUnit.DAYS, new ArrayBlockingQueue<Runnable>(100));
    private ExecutorService singlePool = Executors.newSingleThreadExecutor(new ThreadFactory() {
        public Thread newThread(Runnable r) {
            return null;
        }
    });
    private ExecutorService fixPool = Executors.newFixedThreadPool(4);
    private ScheduledExecutorService schedulePool = Executors.newScheduledThreadPool(1);
    private ExecutorService cachedPool = Executors.newCachedThreadPool();

    public static void main(String[] args){
        MyThreadPool myThreadPool = new MyThreadPool();
        for(int i=0; i<100; i++){
            myThreadPool.executorService.execute(new MyThread());
        }

        for(int i=0; i<100 ; i++){
            myThreadPool.schedulePool.schedule(new MyCallable(),1000,TimeUnit.SECONDS);
        }

        for(int i=0; i<100 ; i++){
            Future<Integer> future = myThreadPool.fixPool.submit(new MyCallable());
            try {
                Integer integer = future.get();
                System.out.println(integer);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }

}
